package com.hxzy.module.merchant.controller;

import com.hxzy.framework.common.resp.R;
import com.hxzy.framework.common.resp.ResultCode;
import com.hxzy.framework.web.util.WebFrameworkUtils;
import com.hxzy.module.merchant.api.merchant.resp.MerchantResp;
import com.hxzy.module.merchant.entity.Merchant;
import com.hxzy.module.merchant.mapstruct.MerchantMapStruct;
import com.hxzy.module.merchant.service.MerchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @Author wy
 * @Description 商户管理
 * @Date 2024/1/24 9:26
 * @Version 1.0
 */
@RestController
@RequestMapping("/merchant")
@Api(tags = "商户模块-商户API")
public class MerchantController {

    @Autowired
    private MerchantService  merchantService;


    @ApiOperation(value="获取商户详情")
    @GetMapping("/detail")
    public R<MerchantResp> getMerchantDetail() {
        long merchantId = WebFrameworkUtils.getMerchantId();
        return R.success(merchantService.getMerchantDetail(merchantId));
    }


    @ApiOperation(value = "根据主键查询")
    @GetMapping(value = "/{id}")
    public R<MerchantResp> findById(@PathVariable(value = "id") Long id){
        Merchant merchant = this.merchantService.getById(id);
        if(Objects.isNull(merchant)){
            return R.failed(ResultCode.DATA_NOT_FOUND);
        }
        return R.success(MerchantMapStruct.INSTANCE.convert(merchant));
    }


}
